<?php

namespace app\index\controller;

use think\Session;
use think\Db;

/**
 * Description of Admin
 *
 * @author ycc
 */
class Show extends Common
{

    //仓库上班明细表检阅
    public function yueDetails()
    {
        if (request()->ispost()) {
            $date     = request()->param('date');
            $times    = request()->param('type');
            $plate    = 'details';//request()->param('plate');
            $userInfo = $this->userInfo;
            if (!in_array($userInfo['id'], [31, 46])) exit(json_encode(['status' => 'error', 'msg' => '无此权限']));

            $save['date']    = $date;
            $save['plate']   = $plate;
            $save['times']   = $times;
            $save['uid']     = $userInfo['id'];
            $save['uname']   = $userInfo['name'];
            $save['addtime'] = time();
            $re              = Db::table('felee_sumchayue_info')->insert($save);
            if ($re) {
                exit_jsons(['status' => 'success', 'msg' => '今日审核成功']);
            }
            exit_jsons(['status' => 'error', 'msg' => '今日还未确认审核', 'data' => '']);
        }
    }

    //仓库上班明细详情
    public function details()
    {
        $userInfo = $this->userInfo;
        /*if(!$userInfo['id']){
            $this->redirect('http://oa.felee.cn/login');
        }*/
        if (request()->isget()) {
            $date = request()->param('date');
            $date = ($date == 'index.php' || !$date) ? date('Y-m-d') : $date;

            $uInfo = Db::table('felee_details_info')->where(['date' => $date, 'display' => 0])->select();

            $sum               = count($uInfo);
            $data['newshenhe'] = $userInfo['name'];
            $data['sum']       = $sum;
            $data['date']      = $date;
            $data['uInfo']     = $uInfo;
            $data['fchayue']   = '';
            $data['tchayue']   = '';
            $fchayueInfo       = Db::table('felee_sumchayue_info')->where(['date' => $date, 'plate' => 'details', 'times' => 1])->find();
            $fchayueInfo && $data['fchayue'] = '已阅时间:' . date('Y-m-d H:i:s', $fchayueInfo['addtime']);
            $tchayueInfo = Db::table('felee_sumchayue_info')->where(['date' => $date, 'plate' => 'details', 'times' => 2])->find();
            $tchayueInfo && $data['tchayue'] = '已阅时间:' . date('Y-m-d H:i:s', $tchayueInfo['addtime']);

            $this->assign('data', $data);

            return $this->fetch('show/details');
        }
    }


    //工资审查
    public function salaryApi()
    {
        $userInfo = $this->userInfo;
        if (request()->isget()) {

            $id = request()->param('id');

            //$salary_name = cookie('salary_name');
            if ($salary_name == '') {
                $uInfos      = Db::table('felee_wages_info')
                    ->where(['id' => $id])
                    ->find();
                $salary_name = $uInfos['name'];
            }


            $where['name'] = $salary_name;

            if ($id) {
                if ($page = request()->param('page')) {
                    //$where['playmonth'] = $page;
                    /* $list = Db::table('felee_wages_info')
                         ->where($where)
                         ->order('addtime desc')
                         ->distinct('date')
                         ->paginate(1);*/
                    //unset($where['playmonth']);
                    //$uInfo = $list[0];


                    $uInfo = Db::table('felee_wages_info')
                        ->where(['playmonth' => $page, 'name' => $salary_name])
                        ->order('addtime desc')
                        ->find();
                } else {
                    $uInfo = Db::table('felee_wages_info')
                        ->where(['id' => $id])
                        ->find();
                }
            }

            cookie('salary_name', $uInfo['name']);

            $salary_name   = cookie('salary_name');
            $where['name'] = $salary_name;
            $list          = Db::table('felee_wages_info')
                ->where($where)
                ->order('addtime desc')
                ->distinct('date')
                ->paginate(1);

            $data['isshenhe']   = 0;
            $data['shenhename'] = '等待李总审查通过';
            if ($uInfo['status'] == 0 && in_array($this->userInfo['id'], [54, 31, 46])) {
                $data['isshenhe'] = 1;
                $data['idt']      = 1;
                $data['idst']     = -1;
            } else if ($uInfo['status'] == 1 && $userInfo['name'] == $uInfo['name']) {
                $data['shenhename'] = '等待' . $uInfo['name'] . '通过';
                $data['isshenhe']   = 1;
                $data['idt']        = 2;
                $data['idst']       = -2;
            } else if ($uInfo['status'] == 1) {
                $data['shenhename'] = '等待' . $uInfo['name'] . '通过';
                $data['isshenhe']   = 0;
            } else if ($uInfo['status'] == 2 && in_array(5, $userInfo['department'])) {
                $data['shenhename'] = '等待财务通过';
                $data['isshenhe']   = 1;
                $data['idt']        = 3;
                $data['idst']       = -3;
            } else if ($uInfo['status'] == 2) {
                $data['shenhename'] = '等待财务通过';
                $data['isshenhe']   = 0;
            } else if ($uInfo['status'] == -1) {
                $data['shenhename'] = '李总已拒绝';
            } else if ($uInfo['status'] == -2) {
                $data['shenhename'] = $uInfo['name'] . '已拒绝';
            } else if ($uInfo['status'] == -3) {
                $data['shenhename'] = '财务已拒绝';
            }
            if ($uInfo['status'] == 3) {
                $data['shenhename'] = '审核已通过';
            }
            //return $uInfo;
            $data['newshenhe'] = $userInfo['name'];
            $data['id']        = $id;
            $oneData['申请编号']   = $uInfo['id'];
            $oneData['申请事项']   = '收入';

            $oneData['部门']  = $uInfo['depart'];
            $oneData["申请人"] = $uInfo['name'];

            $userInfos = Db::table('felee_user')
                ->where(['name' => $uInfo['name']])
                ->find();


            $oneData['入职时间'] = $userInfos['jobdate'];

            $uInfoss = Db::table('felee_wages_info')
                ->where(['name' => $uInfo['name'], 'playmonth' => 8])
                ->order('id desc')
                ->find();

            $uInfo['field34'] == 0 ? $oneData['月最低收入'] = $uInfoss['field34'] : $oneData['月最低收入'] = $uInfo['field34'];
            $uInfo['field35'] == 0 ? $oneData['月最高收入'] = $uInfoss['field35'] : $oneData['月最高收入'] = $uInfo['field35'];


            $oneData['级别']             = $uInfo['lv'] ? 'P' . $uInfo['lv'] : '未设置';
            $oneData["收入"]             = $uInfo['field30'];
            $oneData["上班天数"]           = $uInfo['work_day'];
            $oneData["本次发放金额"]         = $uInfo['field32'];
            $oneData['月业绩未达到标准的保底金额差'] = 0;

            if ($uInfo['field30'] < $oneData['月最低收入']) {  //收入 + 预支小于保底收入
                $saveData               = [];
                $saveData['field32']    = $oneData["本次发放金额"] + $uInfo['field8'] + $uInfo['dcf'];
                $saveData['add_field8'] = 1;
                $status                 = Db::table('felee_wages_info')->where(['id' => $uInfo['id'], 'add_field8' => 0])->update($saveData);
                if ($status) $oneData["本次发放金额"] = $oneData["本次发放金额"] + $uInfo['field8'];
                $j['tips']["本次发放金额"]       = "因业绩较差当月收入低于保底工资的金额差，金额差会计算到下个月盈利后补回或者后续月份 ，如累计金额差非常巨大则会被淘汰调岗或以至开除。";
                $oneData['月业绩未达到标准的保底金额差'] = "-" . ($oneData['月最低收入'] - $uInfo['field30']);
                $oneData["本次发放金额"]         = $oneData['月最低收入'] - $uInfo['field31'] + $uInfo['field8'] - $uInfo['field24'] + $uInfo['dcf'];
                $saveData['add_field8']    = 1;
                $saveData['field32']       = $oneData["本次发放金额"];
                Db::table('felee_wages_info')->where(['id' => $uInfo['id']])->update($saveData);
            }

            /**
             * $saveData               = [];
             * $saveData['field32']    = $oneData["本次发放金额"] + $uInfo['field8'];
             * $saveData['add_field8'] = 1;
             * $status                 = Db::table('felee_wages_info')->where(['id' => $uInfo['id'], 'add_field8' => 0])->update($saveData);
             **/
            //$status = Db::table('felee_wages_info')->where(['id' => $uInfo['id']])->update($saveData);
            // if ($status) $oneData["本次发放金额"] = $oneData["本次发放金额"] + $uInfo['field8'];


            if ($oneData['月最高收入'] < $oneData["本次发放金额"] && $oneData['月最高收入'] != 0) {

                $saveData               = [];
                $saveData['field32']    = $oneData["本次发放金额"] + $uInfo['field8'] + $uInfo['dcf'];
                $saveData['add_field8'] = 1;
                $status                 = Db::table('felee_wages_info')->where(['id' => $uInfo['id'], 'add_field8' => 0])->update($saveData);
                if ($status) $oneData["本次发放金额"] = $oneData["本次发放金额"] + $uInfo['field8'] + $uInfo['dcf'];
                $oneData["本次发放金额"]   = $oneData['月最高收入'];
                $saveData['field32'] = $oneData["本次发放金额"];
                Db::table('felee_wages_info')->where(['id' => $uInfo['id']])->update($saveData);
            }

            $oneData["浮动薪资"] = $uInfo['field8'] + $uInfo['dcf'];
            $oneData['打款单号'] = $uInfo['order'] ? $uInfo['order'] : '无';
            $oneData['打款备注'] = $uInfo['order'] ? $uInfo['name'] . $uInfo['playmonth'] . '月份收入' : '无';
            $oneData['基础收入'] = $uInfo['field1'] . '元';
            // $oneData['月最低收入'] = $uInfo['field34'] . '元';
            //  $oneData['月最高收入'] = $uInfo['field35'] . '元';
            $oneData['月运营链接毛利排行'] = '';


            /*  $oneData['月最低收入']  .= '元';
              $oneData['月最高收入'] .= '元';*/

            $oneData['月运营链接毛利分成'] = '';
            if ($uInfo['name'] == '孙小松') {
                $j['tips']['刷单提成'] = " 一共是15940单，一单是0.05分 总金额是797元";
            }

            if ($uInfo['playmonth'] == 6) {
                switch ($uInfo['name']) {
                    case  "孙小松":
                        $j['tips']["个人提成"] = "15940*0.05=797元";
                        break;
                    case  "刘美君":
                        unset($j['tips']["本次发放金额"]);
                        $oneData["本次发放金额"] = $uInfo['field30'];
                        break;
                }
            }
            if ($uInfo['playmonth'] == 7) {
                switch ($uInfo['name']) {
                    case  "孙小松":
                        //$j['tips']["个人提成"] = "孙小松个人提成绑定店铺23个";
                        $j['tips']["月商家续费奖金2"] = "绑定23个店铺， 40元一个 ";

                        break;
                    case  "刘美君":
                        $j['tips']["个人提成"]     = "拉徒弟6591个， 1毛钱一个";
                        $j['tips']["月商家续费奖金2"] = "新绑定店铺20个，金额40元一个 ";

                        break;
                }
            }
            $oneData['双11当天销售排名奖金']   = 0;
            $j['tips']["双11当天销售排名奖金"] = "0";
            $j['img']["奖金池"]          = '';
            $j['img']["个人提成"]         = '';
            $oneData['双十一奖金池']        = $uInfo['jjc'];

            if ($uInfo['playmonth'] == 12) {

                if ($uInfo['name'] == '胡宁丽' || $uInfo['name'] == '徐晓萍' || $uInfo['name'] == '吴丽君')
                    $j['img']["奖金池"] = 'http://acg.pm/images/2019/01/14/8B9MA5XDC_WIKGKTF8.png';
                if ($uInfo['name'] == '江燕燕' || $uInfo['name'] == '马厚华' || $uInfo['name'] == '李晓燕' || $uInfo['name'] == '李文静' || $uInfo['name'] == '邢慧杰' || $uInfo['name'] == '李艳梅')
                    $j['img']["个人提成"] = 'http://acg.pm/images/2019/01/15/VSDP0FR8NZNM7HXQN0.png';

                if ($uInfo['name'] == '吴碧碧' || $uInfo['name'] == '魏小芳' || $uInfo['name'] == '李玉湘' || $uInfo['name'] == '陈灵荐' || $uInfo['name'] == '董永宁' || $uInfo['name'] == '陈林红' || $uInfo['name'] == '曹雨洁' || $uInfo['name'] == '刘涛')
                    $j['img']["奖金池"] = 'http://acg.pm/images/2019/01/15/4MWS_CLKVJKXMELRXMS.png';

                if ($uInfo['name'] == '吴碧碧' || $uInfo['name'] == '魏小芳' || $uInfo['name'] == '李玉湘' || $uInfo['name'] == '陈灵荐' || $uInfo['name'] == '董永宁' || $uInfo['name'] == '陈林红' || $uInfo['name'] == '曹雨洁' || $uInfo['name'] == '刘涛')
                    $j['img']["个人提成"] = 'http://acg.pm/images/2019/01/15/TAW21MXUH96QN60B.png';
            }

            if ($uInfo['playmonth'] == 11) {

                if ($uInfo['name'] == '陈秋雨' || $uInfo['name'] == '曹纯娟' || $uInfo['name'] == '戴林建' || $uInfo['name'] == '刘美霞' || $uInfo['name'] == '刘聪毅' || $uInfo['name'] == '廖雄')
                    $j['img']["奖金池"] = 'https://apiserver.cc/upload/2018-12-17/ebd7ef69eb1fc1ed80bf5b9af02f8dcb.png';
                if ($uInfo['name'] == '罗锐' || $uInfo['name'] == '吴蔚青' || $uInfo['name'] == '何振清' || $uInfo['name'] == '于丽娜')
                    $j['img']["奖金池"] = 'https://apiserver.cc/upload/2018-12-17/3609b8f5cd4aedac718c4ea6ffc1945b.png';


                switch ($uInfo['name']) {


                    case "刘飞":
                        $j['tips']["个人提成"] = "75380*2%=1507.6";

                        break;
                    case "刘美君":
                        $j['tips']["个人提成"] = "初绑61个 * 40 + 续绑65 * 10 = 3090 ";

                        break;
                    case "邢慧杰":
                        $oneData['双11当天销售排名奖金']   = 1500;
                        $j['tips']["双11当天销售排名奖金"] = "金额22736，奖金1500";
                        break;
                    case "江艳艳":
                        $oneData['双11当天销售排名奖金']   = 1000;
                        $j['tips']["双11当天销售排名奖金"] = "金额18896，奖金1000";
                        break;
                    case "马厚华":
                        $oneData['双11当天销售排名奖金']   = 500;
                        $j['tips']["双11当天销售排名奖金"] = "金额15379，奖金500";
                        break;
                    case "吴丽君":
                        $oneData['双十一部门第一奖金']   = 500;
                        $j['tips']["双十一部门第一奖金"] = "双十一部门第一奖金 500元";
                        break;
                    case "何振清":
                        $oneData['双十一部门第一奖金']   = 1000;
                        $j['tips']["双十一部门第一奖金"] = "双十一部门第一奖金 1000元";
                        break;
                    case "吴蔚青":
                        $oneData['双十一部门第一奖金']   = 500;
                        $j['tips']["双十一部门第一奖金"] = "双十一部门第一奖金 500元";
                        break;
                    case "孙小松":
                        $j['img']["个人提成"] = 'http://acg.pm/images/2018/12/19/1QFEZTJN30GSJG9Y1K.png';
                        break;
                }

            }

            if ($oneData['月运营链接毛利分成'] > 0) {
                //$oneData["收入"] += $oneData['月运营链接毛利分成'];
                // $oneData["本次发放金额"] += $oneData['月运营链接毛利分成'];

                //$re = Db::table('felee_wages_info')->where(['id' => $id])->update(['field30' => $oneData["收入"],'field32' => $oneData["本次发放金额"]]);
            }


            $oneData['月累计剩余未发放金额'] = 0;
            if ($uInfo['field30'] > $uInfo['field35'] && $uInfo['field35'] != 0) {
                $oneData['月累计剩余未发放金额'] = bcsub($oneData["收入"], $uInfo['field35'], 2) . '元';
            }
            if ($uInfo['field36'] != 0) {
                $oneData['月累计剩余未发放金额'] = $uInfo['field36'];
            }

            $oneData["第一审核人"] = '';
            $oneData["第二审核人"] = '';
            $oneData["第三审核人"] = '';
            $uInfo['fs'] && $oneData["第一审核人"] = $uInfo['fs'] . ' ' . date('m-d', $uInfo['fstime']);
            $uInfo['tws'] && $oneData["第二审核人"] = $uInfo['tws'] . ' ' . date('m-d', $uInfo['twstime']);
            $uInfo['ths'] && $oneData["第三审核人"] = $uInfo['ths'] . ' ' . date('m-d', $uInfo['thstime']);

            $oneData["加班费"]   = $uInfo['field3'] ? $uInfo['field3'] : 0;
            $j['tips']["加班费"] = "技术部-美工按照10元/小时计算，助理加班按照5元/小时,2小时的按照10元/小时计算(9月15日后仅客服有加班费，10元/小时)";


            $oneData["加班奖金"]   = $uInfo['field4'] ? $uInfo['field4'] : 0;
            $j['tips']["加班奖金"] = "加班时长第一名奖励700元，第二名奖励500元，第三名奖励200元";

            $oneData['爆款模式奖金池']  = $uInfo['jjcfp'];
            $oneData['综合模式提成']   = $uInfo['ljtc'];
            $oneData['爆款模式排名奖金'] = $uInfo['bktc'];
            $oneData['综合模式排名奖金'] = $uInfo['zhtc'];
            $oneData['打车费']      = $uInfo['dcf'];
            $oneData['其他奖金']     = $uInfo['qtjj'];

            $oneData['假日加班费'] = $uInfo['field6'] ? $uInfo['field6'] : 0;
            $oneData['未休假费']  = $uInfo['field8'] ? $uInfo['field8'] : 0;
            $oneData["住宿补贴"]  = $uInfo['field9'] ? $uInfo['field9'] : 0;
            $oneData['岗位补贴']  = $uInfo['field10'] ? $uInfo['field10'] : 0;
            $oneData['话费补贴']  = $uInfo['field11'] ? $uInfo['field11'] : 0;
            $oneData['生日福利']  = $uInfo['field12'] ? $uInfo['field12'] : 0;
            $oneData['全勤']    = $uInfo['field13'] ? $uInfo['field13'] : 0;
            $oneData['主管授权奖'] = $uInfo['field14'] ? $uInfo['field14'] : 0;
            $oneData["奖金池"]   = $uInfo['field15'] ? $uInfo['field15'] : 0;
            $j['tips']["奖金池"] = '根据加班时长,贡献，配合度来进行评估';

            //$oneData["其他奖金"]      = $uInfo['field16'] ? $uInfo['field16'] : 0;
            $oneData['月商家续费奖金']   = $uInfo['field17'] ? $uInfo['field17'] : 0;
            $j['tips']["月商家续费奖金"] = '首次非试用绑定商家奖励40元，续费商家一个奖励60元';

            $oneData['公司当日销售额最高'] = $uInfo['field18'] ? $uInfo['field18'] : 0;
            if ($uInfo['depart'] == '客服') {
                $oneData["客服旺旺绩效提成"]   = $uInfo['field19'] ? $uInfo['field19'] : 0;
                $j['tips']["客服旺旺绩效提成"] = "百分一个点，销售额第一的奖励1000元，美工评分最高的奖励1000元";

            } else {

                if (!$oneData['月运营链接毛利分成']) {
                    $oneData["个人提成"] = $uInfo['field19'] ? $uInfo['field19'] : 0;
                }


            }


            if ($uInfo['name'] == '徐晓红')
                $oneData["月累计剩余未发放金额"] = "211.2";
            $j['tips']["月其他个人奖励提成"] = $uInfo['field19note'];
            $oneData["公司分成"]        = $uInfo['field33'] ? $uInfo['field33'] : 0;
            $j['tips']["公司分成"]      = "月公司分成由月销售额及利润及加班工作配合表现所大致得到，具备临时性，当有股份时取消或有业务提成时取消该分成。";

            $oneData['现金奖励']        = $uInfo['cashreward'] ? $uInfo['cashreward'] . "(已领取)" : 0;
            $oneData['客服当日销售额最高奖励'] = $uInfo['field20'] ? $uInfo['field20'] : 0;
            $oneData['客服月销售额排名奖励']  = $uInfo['field21'] ? $uInfo['field21'] : 0;
            $oneData['客服月销售额达标奖励']  = $uInfo['field22'] ? $uInfo['field22'] : 0;
            $oneData['请假扣除']        = $uInfo['field24'] ? $uInfo['field24'] : 0;
            $oneData['迟到/早退扣除']     = $uInfo['field25'] ? $uInfo['field25'] : 0;
            $oneData['公司奖惩']        = $uInfo['field26'] ? $uInfo['field26'] : 0;
            $oneData['水电费']         = $uInfo['field27'] ? $uInfo['field27'] : 0;
            $oneData['社保扣除']        = $uInfo['field28'] ? $uInfo['field28'] : 0;
            $oneData['未打卡扣款']       = $uInfo['field29'] ? $uInfo['field29'] : 0;
            $oneData['预支工资']        = $uInfo['field31'] ? $uInfo['field31'] : 0;
            $oneData['加班工时(小时)']    = $uInfo['field2'] ? $uInfo['field2'] : 0;
            $oneData['请假天数']        = $uInfo['field23'] ? $uInfo['field23'] : 0;
            $oneData['假日加班天数']      = $uInfo['field5'] ? $uInfo['field5'] : 0;
            $oneData['未休假天数']       = $uInfo['field7'] ? $uInfo['field7'] : 0;
            $oneData['申请时间']        = date('Y-m-d H:i:s', $uInfo['addtime']);
            $oneData['收款人姓名']       = $uInfo['name'];
            $oneData['打款状态']        = $uInfo['is_play'] == 1 ? '已打款' : '未打款';
            $oneData['审核状态']        = $data['shenhename'];


            if ($uInfo['money_type'] == 2) {
                //$oneData['收款方式'] = $uInfo['name'] . '微信宝';
                $oneData['收款账号'] = $uInfo['name'] . '微信宝';
            } else if ($uInfo['money_type'] == 3) {
                $oneData['收款方式'] = $uInfo['name'] . '支付宝';
                //$oneData['收款账号'] = $uInfo['name'] . '微信宝';
            } else {
                //$oneData['收款方式'] = '未选择';
                $oneData['收款账号'] = '未选择';
            }
            $oneData['KPI']  = '未设置';
            $oneData['绩效标准'] = '未设置';


            $j['tips']['月运营链接毛利分成'] = '根据月运营链接毛利最低1%理论得到，如未算出毛利或统计数据丢失，则按总奖金池排行榜个人大致所占团队利润比计算分成。';
            $oneData['备注']          = $uInfo['remark'] ?: '暂无';
            $last_date_begin        = $uInfo['playmonth'] ? $uInfo['playmonth'] : date('m', strtotime('-1 month', $uInfo['addtime']));

            $data['uInfo'] = $oneData;
            $this->assign('last_date', $last_date_begin . '月 ');
            $this->assign('data', $data);
            $this->assign('name', $uInfo['name']);
            $this->assign('remark2', $uInfo['remark2']);
            if (isset($list)) {
                $this->assign('page', $list);
            }

            if ($uInfo['name'] == $this->userInfo['name']) {
                $this->assign('wage_type', 1);
                $j['wage_type'] = 1;
            }
            unset($data['uInfo']);
            $j['remark2'] = $uInfo['remark2'];
            $j['datas']   = $data;
            $j['data']    = $oneData;
            $j['admin']   = $userInfo['name'];
            $j['user']    = $salary_name;
            $j['month']   = $last_date_begin;

            switch ($uInfo['depart']) {
                case "客服":
                    break;
                case "美工":
                    break;
                case "人事":
                    break;
                case "技术部":
                    break;
                case "运营助理":
                    break;
                case "运营部":
                    break;
                case "客服主管":
                    break;
                case  "仓库":
                    break;
            }

            if (request()->param('callback')) {
                exit(request()->param('callback') . "(" . json_encode($j) . ")");
            }
            exit(json_encode($j));
        }
    }


    //工资审查
    public function salary()
    {
        $userInfo = $this->userInfo;
        if (request()->isget()) {

            $id = request()->param('id');

            $salary_name   = cookie('salary_name');
            $where['name'] = $salary_name;

            if ($id) {
                if ($page = request()->param('page')) {
                    $list = Db::table('felee_wages_info')
                        ->where($where)
                        ->order('addtime desc')
                        ->distinct('date')
                        ->paginate(1);

                    $uInfo = $list[0];
                } else {
                    $uInfo = Db::table('felee_wages_info')
                        ->where(['id' => $id])
                        ->find();
                }
            }

            cookie('salary_name', $uInfo['name']);

            $salary_name   = cookie('salary_name');
            $where['name'] = $salary_name;
            $list          = Db::table('felee_wages_info')
                ->where($where)
                ->order('addtime desc')
                ->distinct('date')
                ->paginate(1);

            $data['isshenhe']   = 0;
            $data['shenhename'] = '等待李总审查通过';
            if ($uInfo['status'] == 0 && in_array($this->userInfo['id'], [54, 31, 46])) {
                $data['isshenhe'] = 1;
                $data['idt']      = 1;
                $data['idst']     = -1;
            } else if ($uInfo['status'] == 1 && $userInfo['name'] == $uInfo['name']) {
                $data['shenhename'] = '等待' . $uInfo['name'] . '通过';
                $data['isshenhe']   = 1;
                $data['idt']        = 2;
                $data['idst']       = -2;
            } else if ($uInfo['status'] == 1) {
                $data['shenhename'] = '等待' . $uInfo['name'] . '通过';
                $data['isshenhe']   = 0;
            } else if ($uInfo['status'] == 2 && in_array(5, $userInfo['department'])) {
                $data['shenhename'] = '等待财务通过';
                $data['isshenhe']   = 1;
                $data['idt']        = 3;
                $data['idst']       = -3;
            } else if ($uInfo['status'] == 2) {
                $data['shenhename'] = '等待财务通过';
                $data['isshenhe']   = 0;
            } else if ($uInfo['status'] == -1) {
                $data['shenhename'] = '李总已拒绝';
            } else if ($uInfo['status'] == -2) {
                $data['shenhename'] = $uInfo['name'] . '已拒绝';
            } else if ($uInfo['status'] == -3) {
                $data['shenhename'] = '财务已拒绝';
            }
            if ($uInfo['status'] == 3) {
                $data['shenhename'] = '审核已通过';
            }
            //return $uInfo;
            $data['newshenhe'] = $userInfo['name'];
            $data['id']        = $id;
            $oneData['申请编号']   = $uInfo['number'];
            $oneData['申请事项']   = '工资';

            $oneData['部门']   = $uInfo['depart'];
            $oneData['入职时间'] = $userInfo['jobdate'];

            $oneData["<span style='color:red'>申请人</span>"] = "<span style='color:red'>" . $uInfo['name'] . "</span>";

            $oneData["<span style='color:red'>收入</span>"]                                 = "<span style='color:blue'>" . $uInfo['field30'] . '元' . "</span>";
            $oneData["<span style='color:red;' title={$uInfo['remark']}>本次发放金额  </span>"] = "<span style='color:blue'>" . $uInfo['field32'] . '元' . '</span>';
            $oneData['基础工资']                                                              = $uInfo['field1'] . '元';
            $uInfo['fs'] && $oneData["<span style='color:red'>第一审核人</span>"] = "<span style='color:red'>" . $uInfo['fs'] . ' ' . date('m-d', $uInfo['fstime']) . "</span>";
            $uInfo['tws'] && $oneData["<span style='color:red'>第二审核人</span>"] = "<span style='color:red'>" . $uInfo['tws'] . ' ' . date('m-d', $uInfo['twstime']) . "</span>";
            $uInfo['ths'] && $oneData["<span style='color:red'>第三审核人</span>"] = "<span style='color:red'>" . $uInfo['ths'] . ' ' . date('m-d', $uInfo['thstime']) . "</span>";

            $oneData["<span title='技术部-美工按照10元/小时计算，助理加班按照5元/小时,2小时的按照10元/小时计算' >加班费</span>"] = $uInfo['field3'] ? "<span style='color:blue'>" . $uInfo['field3'] . '元' . "</span>" : 0 . '元';
            $oneData["<span title='加班时长第一名奖励700元，第二名奖励500元，第三名奖励200元'>加班奖金</span>"]           = $uInfo['field4'] ? "<span style='color:blue'>" . $uInfo['field4'] . '元' . "</span>" : 0 . '元';
            $oneData['假日加班费']                                                                 = $uInfo['field6'] ? "<span style='color:blue'>" . $uInfo['field6'] . '元' . "</span>" : 0 . '元';
            $oneData['未休假费']                                                                  = $uInfo['field8'] ? "<span style='color:blue'>" . $uInfo['field8'] . '元' . "</span>" : 0 . '元';
            $oneData["<span title='未住员工宿舍的，每月住房补贴300/月'>住宿补贴</span>"]                         = $uInfo['field9'] ? "<span style='color:blue'>" . $uInfo['field9'] . '元' . "</span>" : 0 . '元';
            $oneData['岗位补贴']                                                                  = $uInfo['field10'] ? "<span style='color:blue'>" . $uInfo['field10'] . '元' . "</span>" : 0 . '元';
            $oneData['话费补贴']                                                                  = $uInfo['field11'] ? "<span style='color:blue'>" . $uInfo['field11'] . '元' . "</span>" : 0 . '元';
            $oneData['生日福利']                                                                  = $uInfo['field12'] ? "<span style='color:blue'>" . $uInfo['field12'] . '元' . "</span>" : 0 . '元';
            $oneData['全勤']                                                                    = $uInfo['field13'] ? "<span style='color:blue'>" . $uInfo['field13'] . '元' . "</span>" : 0 . '元';
            $oneData['主管授权奖']                                                                 = $uInfo['field14'] ? "<span style='color:blue'>" . $uInfo['field14'] . '元' . "</span>" : 0 . '元';
            $oneData["<span title='根据加班时长,贡献，配合度来进行评估'>优秀员工奖</span>"]                         = $uInfo['field15'] ? "<span style='color:blue'>" . $uInfo['field15'] . '元' . "</span>" : 0 . '元';
            $oneData["特殊奖金"]                                                                  = $uInfo['field16'] ? "<span style='color:red'>" . $uInfo['field16'] . '元' . "</span>" : 0 . '元';
            $oneData['客分享奖金']                                                                 = $uInfo['field17'] ? "<span style='color:blue'>" . $uInfo['field17'] . '元' . "</span>" : 0 . '元';
            $oneData['公司当日销售额最高']                                                             = $uInfo['field18'] ? "<span style='color:blue'>" . $uInfo['field18'] . '元' . "</span>" : 0 . '元';
            if ($uInfo['depart'] == '客服') {
                $oneData["<span style='color:red' title='百分一个点，销售额第一的奖励1000元，美工评分最高的奖励1000元'>客服旺旺绩效提成</span>"] = $uInfo['field19'] ? "<span style='color:blue'>" . $uInfo['field19'] . '元' . "</span>" : "<span style='color:red'>" . 0 . "元</span>";
            } else {

                if ($uInfo['name'] == '孙小松' || $uInfo['name'] == '刘美君') {
                    $oneData["<span style='color:red' title=''>个人提成</span>"] = $uInfo['field19'] ? "<span style='color:blue'>" . $uInfo['field19'] . '元' . "</span>" : "<span style='color:red'>" . 0 . "元</span>";

                } else {
                    $oneData["<span style='color:red' title='百分一个点，销售额第一的奖励1000元，美工评分最高的奖励1000元'>个人提成</span>"] = $uInfo['field19'] ? "<span style='color:blue'>" . $uInfo['field19'] . '元' . "</span>" : "<span style='color:red'>" . 0 . "元</span>";

                }
            }


            $oneData['公司分成'] = $uInfo['field33'] ? "<span style='color:red'>" . $uInfo['field33'] . '元' . "</span>" : 0 . '元';


            $oneData['现金奖励']        = $uInfo['cashreward'] ? "<span style='color:red'>" . $uInfo['cashreward'] . '元（已领取）' . "</span>" : 0 . '元';
            $oneData['客服当日销售额最高奖励'] = $uInfo['field20'] ? "<span style='color:blue'>" . $uInfo['field20'] . '元' . "</span>" : 0 . '元';
            $oneData['月销售额排名奖励']    = $uInfo['field21'] ? "<span style='color:blue'>" . $uInfo['field21'] . '元' . "</span>" : 0 . '元';
            if ($uInfo['name'] == '刘美君') {
                $oneData['月运营产品分成'] = $uInfo['field22'] ? "<span style='color:blue'>" . $uInfo['field22'] . '元' . "</span>" : 0 . '元';
            } else {
                $oneData['月销售额达标奖励'] = $uInfo['field22'] ? "<span style='color:blue'>" . $uInfo['field22'] . '元' . "</span>" : 0 . '元';
            }


            $oneData['请假扣除']     = $uInfo['field24'] ? "<span style='color:red'>" . $uInfo['field24'] . '元' . "</span>" : 0 . '元';
            $oneData['迟到/早退扣除']  = $uInfo['field25'] ? "<span style='color:red'>" . $uInfo['field25'] . '元' . "</span>" : 0 . '元';
            $oneData['违规扣除']     = $uInfo['field26'] ? "<span style='color:red'>" . $uInfo['field26'] . '元' . "</span>" : 0 . '元';
            $oneData['水电费']      = $uInfo['field27'] ? "<span style='color:red'>" . $uInfo['field27'] . '元' . "</span>" : 0 . '元';
            $oneData['社保扣除']     = $uInfo['field28'] ? "<span style='color:red'>" . $uInfo['field28'] . '元' . "</span>" : 0 . '元';
            $oneData['未打卡扣款']    = $uInfo['field29'] ? "<span style='color:red'>" . $uInfo['field29'] . '元' . "</span>" : 0 . '元';
            $oneData['预支工资']     = $uInfo['field31'] ? "<span style='color:red'>" . $uInfo['field31'] . '元' . "</span>" : 0 . '元';
            $oneData['加班工时(小时)'] = $uInfo['field2'] ? $uInfo['field2'] . '小时' : 0 . '小时';
            $oneData['请假天数']     = $uInfo['field23'] ? $uInfo['field23'] . '天' : 0 . '天';
            $oneData['假日加班天数']   = $uInfo['field5'] ? $uInfo['field5'] . '天' : 0 . '天';
            $oneData['未休假天数']    = $uInfo['field7'] ? $uInfo['field7'] . '天' : 0 . '天';
            $oneData['申请时间']     = date('Y-m-d H:i:s', $uInfo['addtime']);
            $oneData['收款人姓名']    = $uInfo['name'];
            $oneData['打款状态']     = $uInfo['is_play'] == 1 ? '已打款' : '未打款';
            $oneData['审核状态']     = $data['shenhename'];
            if ($uInfo['money_type'] == 2) {
                $oneData['收款方式'] = '微信宝';
            } else if ($uInfo['money_type'] == 3) {
                $oneData['收款方式'] = '支付宝';
            } else {
                $oneData['收款方式'] = '未选择';
            }
            $oneData['备注']   = $uInfo['remark'] ?: '暂无';
            $last_date_begin = $uInfo['playmonth'] ? $uInfo['playmonth'] : date('m', strtotime('-1 month', $uInfo['addtime']));

            $data['uInfo'] = $oneData;
            $this->assign('last_date', $last_date_begin . '月 ');
            $this->assign('data', $data);
            $this->assign('name', $uInfo['name']);
            $this->assign('remark2', $uInfo['remark2']);
            if (isset($list)) {
                $this->assign('page', $list);
            }

            if ($uInfo['name'] == $this->userInfo['name']) {
                $this->assign('wage_type', 1);
            }
            return $this->fetch();
        }
    }

    //设置打款方式
    public function setWageType()
    {

        $infoData = request()->param('data');
        $infoData = json_decode($infoData, true);
        $list     = Db::table('felee_wages_info')
            ->where('id', $infoData['id'])
            ->update(['money_type' => $infoData['status']]);
        $list && exit(json_encode(['status' => 1, 'msg' => '修改成功']));
    }

    //添加手动备注
    public function addremark()
    {
        $infoData = request()->param('data');
        $infoData = json_decode($infoData, true);

        if (!in_array($this->userInfo['id'], [122299, 46])) {
            //exit('无权添加');
        }
        $data = Db::table('felee_wages_info')->where('id', $infoData['id'])->update(['remark2' => $infoData['remark']]);
        if ($data) {
            return json("备注成功");
        } else {
            return json("备注失败");
        }
    }

    // 工作总结复制按钮
    public function myWorkInfo()
    {
        $id = request()->param('id');
        if (!$id) exit(json_encode(['status' => 400, 'message' => '链接错误', 'data' => '']));
        $data = Db::name('work_info')->where(['id' => $id])->find();
        if (!$data) exit(json_encode(['status' => 400, 'message' => '链接错误', 'data' => '']));
        exit(json_encode(['status' => 200, 'message' => '', 'data' => $data]));
    }

    public function todayDaka(){
        $date = request()->param('date');
        $date = $date ?$date:date('Y-m-d');
        if(!$date) exit(json_encode(['status'=>400,'message'=>'链接错误','data'=>'']));
        $list = Db::name('daka')->where("DATE_FORMAT( time, '%Y-%m-%d' ) = '".$date."' ")->order('time asc')->select();
        if(!$list) exit(json_encode(['status'=>400,'message'=>'链接错误','data'=>'']));
        exit(json_encode(['status'=>200,'message'=>'','data'=>$list]));
    }
}
